# -*- coding:utf-8 -*-
import uuid

from django.db import models

from Apps.util.snowFlake import get_guid
from Main.settings import AUTH_USER_MODEL

"""
自定义模型类
"""


class CustomModel(models.Model):
    # id = models.CharField(max_length=50, primary_key=True, default=uuid.uuid4, help_text="Id", verbose_name="Id")
    id = models.CharField(max_length=20, primary_key=True, default=get_guid, editable=False, help_text="Id",
                          verbose_name="Id")
    create_time = models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, db_index=True, verbose_name='修改时间', null=True)

    class Meta:
        abstract = True


class ModifyModel(CustomModel):
    creator = models.CharField(max_length=50, verbose_name="创建人", null=True)
    modifier = models.CharField(max_length=50, verbose_name="修改人", null=True)

    class Meta:
        abstract = True

"""
报错：
(fields.E300) Field defines a relation with model 'User', which is either not installed, or is abstract.
(fields.E307) The field System.Role.creator was declared with a lazy reference to 'System.user', but app 'System' doesn't provide model 'user'.
原因：跨app建表时，有外键，或者一对一，一对多字段。
解决：在字段关联表前，加上APP的名称 to='User.User'
"""


"""

class CoreModel(models.Model):

    id = models.CharField(max_length=255, primary_key=True, default=uuid.uuid4, help_text="Id", verbose_name="Id")
    description = models.CharField(max_length=255, verbose_name="描述", null=True, blank=True, help_text="描述")
    creator = models.ForeignKey(to=settings.AUTH_USER_MODEL, related_query_name='creator_query', null=True,
                                verbose_name='创建人', help_text="创建人", on_delete=models.SET_NULL, db_constraint=False)
    modifier = models.CharField(max_length=255, null=True, blank=True, help_text="修改人", verbose_name="修改人")
    dept_belong_id = models.CharField(max_length=255, help_text="数据归属部门", null=True, blank=True, verbose_name="数据归属部门")
    update_datetime = models.DateTimeField(auto_now=True, null=True, blank=True, help_text="修改时间", verbose_name="修改时间")
    create_datetime = models.DateTimeField(auto_now_add=True, null=True, blank=True, help_text="创建时间",
                                           verbose_name="创建时间")

    class Meta:
        abstract = True
        verbose_name = '核心模型'
        verbose_name_plural = verbose_name

"""
